package cz.data.common.core;

import lombok.AllArgsConstructor;
import lombok.Getter;

public class DataConstant {

    public static class DB_METADATA {
        public static final String ES_FIELD_DESCRIBE_KEY = "description";
    }

    public static class SERVICE_EXT {
        public static final String SERVICE_NO_HEADER = "X-Service-No";

        public static class RequestParamType {
            public static final String PATH = "path";
            public static final String HEADER = "header";
            public static final String BODY = "body";
        }
    }

    public static class Token {
        public static final String JWT_CACHE_PREFIX = "jwt_jti:";
        public static final String JTI_CACHE_PREFIX = "auth:userinfo:";
        public static final String USER_HEADER = "Authorization";
        public static final String SERVICE_HEADER = "X-Service-Token";
        public static final String GATEWAY_HEADER = "X-Gateway-Flag";
        public static final String TOKEN_JTI_HEADER = "X-Token-Id";
    }

    @Getter
    @AllArgsConstructor
    public enum ElasticsearchIndexModel {
        Normal("1", "普通索引"),
        Roll("2", "滚动索引"),
        Stream("3", "数据流"),
        ;

        private final String value;
        private final String name;

        public boolean equalsValue(String value) {
            return this.value.equalsIgnoreCase(value);
        }
    }

    public enum SourceCapability {
        SOURCE("输入", "1"),
        SINK("输出", "2"),
        SQL("SQL", "3")
        ;

        private final String name;
        private final String value;


        SourceCapability(String name, String value) {
            this.name = name;
            this.value = value;
        }

        public String getName() {
            return name;
        }

        public String getValue() {
            return value;
        }
    }

    /**
     * Oauth2安全相关常量
     */
    public enum Security {
        //security授权角色前缀
        ROLEPREFIX("ROLE_");

        Security(String val) {
            this.val = val;
        }

        private final String val;

        public String getVal() {
            return val;
        }
    }

    /**
     * 通用的是否
     */
    @Getter
    public enum TrueOrFalse {
        FALSE("0", false),
        TRUE("1", true);

        TrueOrFalse(String key, boolean val) {
            this.key = key;
            this.val = val;
        }

        private final String key;
        private final boolean val;

        public boolean equalsKey(Object key) {
            return this.key.equals(key);
        }

        public static TrueOrFalse parse(String key) {
            for (TrueOrFalse value : TrueOrFalse.values()) {
                if (value.getKey().equals(key)) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 用户认证返回额外信息
     */
    public enum UserAdditionalInfo {
        LICENSE("license", "data-platform"),
        USER("user", "用户"),
        USERID("user_id", "用户ID"),
        USERNAME("username", "用户名"),
        NICKNAME("nickname", "用户昵称"),
        DEPT("user_dept", "用户部门"),
        ROLE("user_role", "用户角色"),
        POST("user_post", "用户岗位");

        UserAdditionalInfo(String key, String val) {
            this.key = key;
            this.val = val;
        }

        private final String key;
        private final String val;

        public String getKey() {
            return key;
        }

        public String getVal() {
            return val;
        }
    }

    /**
     * 通用的启用禁用状态
     */
    public enum EnableState {
        DISABLE("0", "禁用"),
        ENABLE("1", "启用");

        EnableState(String key, String val) {
            this.key = key;
            this.val = val;
        }

        private final String key;
        private final String val;

        public String getKey() {
            return key;
        }

        public String getVal() {
            return val;
        }
    }

    /**
     * 流程审核状态
     */
    public enum AuditState {
        WAIT("1", "待提交"),
        BACK("2", "已退回"),
        AUDIT("3", "审核中"),
        AGREE("4", "通过"),
        REJECT("5", "不通过"),
        CANCEL("6", "已撤销");

        AuditState(String key, String val) {
            this.key = key;
            this.val = val;
        }

        private final String key;
        private final String val;

        public String getKey() {
            return key;
        }

        public String getVal() {
            return val;
        }
    }

    /**
     * 菜单类型
     */
    public enum MenuType {
        MODULE("0", "模块"),
        MENU("1", "菜单"),
        BUTTON("2", "按钮");

        MenuType(String key, String val) {
            this.key = key;
            this.val = val;
        }

        private final String key;
        private final String val;

        public String getKey() {
            return key;
        }

        public String getVal() {
            return val;
        }
    }

    /**
     * 数据范围
     */
    public enum DataScope {
        ALL("1", "全部数据权限"),
        CUSTOM("2", "自定义数据权限"),
        DEPT("3", "本部门数据权限"),
        DEPTANDCHILD("4", "本部门及以下数据权限"),
        SELF("5", "仅本人数据权限");

        DataScope(String key, String val) {
            this.key = key;
            this.val = val;
        }

        private final String key;
        private final String val;

        public String getKey() {
            return key;
        }

        public String getVal() {
            return val;
        }
    }

    /**
     * Api状态
     */
    public enum ApiState {
        WAIT("1", "待发布"),
        RELEASE("2", "已发布"),
        CANCEL("3", "已下线");

        ApiState(String key, String val) {
            this.key = key;
            this.val = val;
        }

        private final String key;
        private final String val;

        public String getKey() {
            return key;
        }

        public String getVal() {
            return val;
        }
    }
}
